<template>
    <div style="margin-top: 60px;">
        <el-row>
            <el-col :md="10" :offset="7">
                <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
                    <el-form-item label="团队名：" prop="team_name">
                        <el-input v-model="ruleForm.team_name" auto-complete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="团队负责人：" prop="team_ruler">
                        <el-select v-model="ruleForm.team_ruler" filterable placeholder="请选择" class="w100">
                            <el-option v-for="item in options1" :key="item.value" :label="item.label" :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="销售成员：" prop="value10">
                        <el-select v-model="ruleForm.value10" multiple filterable allow-create default-first-option placeholder="请选择" class="w100">
                            <el-option v-for="item in options5" :key="item.value" :label="item.label" :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="备注：">
                        <el-input v-model="ruleForm.beizhu" auto-complete="off" ></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
                        <el-button @click="resetForm('ruleForm')">取消</el-button>
                    </el-form-item>
                </el-form>
            </el-col>
        </el-row>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                ruleForm: {
                    team_name: '',
                    team_ruler: '',
                    value10: '',
                    beizhu: ''
                },
                options1: [{
                    value: '选项一',
                    label: '销售'
                }],
                options5: [{
                    value: 'HTML',
                    label: 'HTML'
                }, {
                    value: 'CSS',
                    label: 'CSS'
                }, {
                    value: 'JavaScript',
                    label: 'JavaScript'
                }],
                rules: {
                    team_name: [{
                        required: true,
                        message: '请输入团队名',
                        trigger: 'blur'
                    }],
                    team_ruler: [{
                        required: true,
                        message: '请选择团队负责人',
                        trigger: 'change'
                    }]
                }
            };
        },
        created() {
            this.getData()
            if (this.$route.name == 'admin') {
                this.role = '管理员'
            } else if (this.$route.name == 'sales') {
                this.role = '销售'
            } else if (this.$route.name == 'customer_service') {
                this.role = '客服'
            } else if (this.$route.name == 'finance') {
                this.role = '财务'
            }
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        // if (this.$route.fullPath == '/carriers/new') {
                        //     this.$axios.post('/api/carriers',
                        //         {
                        //             name: this.ruleForm.name,
                        //             contact_person: this.ruleForm.contact_person,
                        //             email: this.ruleForm.email,
                        //             phone_number: this.ruleForm.phone_number,
                        //             carrier_type: this.ruleForm.carrier_type
                        //         }
                        //     ).then((res) => {
                        //         this.$store.commit('setAlert', res.data)
                        //         this.$router.push({
                        //             path: '/carriers'
                        //         })
                        //     })
                        // } else {
                        //     this.$axios.put(
                        //         `/api/carriers/${this.$route.query.id}`,
                        //          {
                        //             name: this.ruleForm.name,
                        //             contact_person: this.ruleForm.contact_person,
                        //             email: this.ruleForm.email,
                        //             phone_number: this.ruleForm.phone_number,
                        //             carrier_type: this.ruleForm.carrier_type
                        //         }
                        //     ).then((res) => {
                        //         this.$store.commit('setAlert', res.data)
                        //         this.$router.push({
                        //                 path: '/carriers'
                        //         })
                        //     })
                        // }
                        console.log(1111)
    
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
                this.$router.push({
                    path: '/carriers'
                })
            },
            // getData() {
            //     this.$axios.get(`/api/carriers/${this.$route.query.id}/edit`).then((res) => {
            //         this.ruleForm.name = res.data.name
            //         this.ruleForm.carrier_type = res.data.carrier_type
            //         this.ruleForm.contact_person = res.data.contact_person
            //         this.ruleForm.email = res.data.email
            //         this.ruleForm.phone_number = res.data.phone_number
            //     })
            // }
        }
    }
</script>

<style lang="scss" scoped>
    .w100 {
        width: 100%;
    }
</style>

